#include <stdio.h>
#include <sys/types.h>
#include <sys/shm.h>
#include <sys/ipc.h>

int main()
{
	key_t key = ftok(".",105);
	if(key == -1)
		perror("ftok") , exit(-1);
	printf("key = %x\n",key);
	int shmid = shmget(key,0,0);
	if(shmid == -1)
		perror("shmget") , exit(-1);
	struct shmid_ds ds ;
	shmctl(shmid,IPC_STAT,&ds);
	printf("key = %x\n",ds.shm_perm.__key);
	printf("perm = %o\n",ds.shm_perm.mode);
	printf("cpid = %d\n",ds.shm_segsz);
	printf("nattch = %d\n",ds.shm_nattch);

	ds.shm_perm.mode = 600;
	ds.shm_segsz = 400;
	shmctl(shmid,IPC_SET,&ds);
	shmctl(shmid,IPC_RMID,0);	//delete shared memory referred to the id
}
